package com.teamone.etl.systemsettings.utils;


import com.teamone.etl.systemsettings.entity.Department;
import com.teamone.etl.systemsettings.entity.Post;
import com.teamone.etl.systemsettings.entity.Userform;
import org.aspectj.lang.ProceedingJoinPoint;

import javax.servlet.http.HttpServletRequest;

import static com.teamone.etl.constant.EtlConstant.Operate.*;

/**
 * 操作日志-详细内容
 *
 * @author huaiyu
 * @create 2021/1/25 11:14
 */
public class OperatingUtils {

    public static String operating(HttpServletRequest request, ProceedingJoinPoint joinPoint) {

        //查看什么类型的请求
        String method = request.getMethod();

        String name = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        //如果是POST请求
        if((IF_POST).equals(method)) {
            //执行此方法
            if((IF_CREATEPOST).equals(name)){
                Post newArg = new Post();
                for (Object arg : args) {
                    newArg = (Post)arg;
                }
                return "添加了岗位:"+newArg.getName();
            }
            if((IF_CREATE_USER_FORM).equals(name)){
                Userform newArg = new Userform();
                for (Object arg : args) {
                    newArg = (Userform) arg;
                }
                return "添加了员工:"+newArg.getUsername();
            }
        }
        if((IF_PUT).equals(method)) {
            if((IF_UPDATE_PASSWORD).equals(name)){
                Object newArg = null;

                for (Object arg : args) {
                    newArg=arg;
                    break;
                }
                return "修改了员工id为："+newArg+"的密码";
            }

        }
        if((IF_GET).equals(method)) {
            if((IF_SELECT_COUNT_POST).equals(name)) {
                Object newArg = null;

                for (Object arg : args) {
                    newArg=arg;
                    break;
                }
                String context = "查询部门id为"+newArg+"下的所有岗位";
                return context;

            }

            if((IF_GET_COUNT_NUMBER).equals(name)) {

                Object newArg = null;

                for (Object arg : args) {
                    newArg=arg;
                    break;
                }
                String context =  "查询岗位id为"+newArg+"的总人数";
                return context;
            }
        }
        if((IF_DELETE).equals(method)) {
            if((IF_DELETE_USER_BY_ID).equals(name)){
                Object newArg = null;

                for (Object arg : args) {
                    newArg=arg;
                    break;
                }
                return "删除了员工:"+newArg;
            }
        }
        return "";
    }

}
